to sync 2 or more postgresql database that exist on seprate server (with specific IP) we have some way.
First we should tell about replication. replication uses when we want to make an backup from current exist postgresql DB. not a fix backup, an streaming replication that replicate each changes in primary DB on others backup DB.
So we can use this to make a mirror server, but what happen if we use write query (e.g. insert, update) on the secondery db (backup db)? ok we should not allow to write on db because every change on backup db cause to dismiss data because new data has been written on that when update from primary db. So what should we do? we should forward write query to primary db and after primary DB changes the replication send new data to backup DB so the user think write on the DB really worked while the write query forwarded to primary DB.
we start with Replication config.
1. Replication
to make an replication server we only need to use this command:
pg_basebackup -D /path/to/new/data/dir -R --slot=some_name -C -h host -p port -U dbuser
it's realy a simple way to make an database for replication. note that this command should be run on the backup server, so `host` should the IP address of primary server.
maybe you can not coect to primary srever because postgresql denied access to db from other remote server (only localhost access is allowed). so to change this you should change below file.
/etc/postgresql/14/main/pg_hba.conf
so you can
برچسب:
نویسنده: سارا زارعیپور
تاريخ: دوشنبه
21 خرداد
1403 ساعت: 16:03